Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to modify and propagate names of columns object #17597

Merged
merged 9 commits into from
Dec 19, 2024

Conversation

galipremsagar
Copy link
Contributor

@galipremsagar galipremsagar commented Dec 14, 2024

Description

Fixes: #17482, #14012

This PR fixes a long-standing issue where modifying columns name never propagates to the parent object. This PR fixes this issue by making to_pandas_index a cached-property and accessing it's names if this property was ever invoked in level_names property.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Copy link

copy-pr-bot bot commented Dec 14, 2024

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@galipremsagar
Copy link
Contributor Author

/okay to test

@github-actions github-actions bot added the Python Affects Python cuDF API. label Dec 14, 2024
@galipremsagar galipremsagar added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Dec 14, 2024
@galipremsagar
Copy link
Contributor Author

/okay to test

@galipremsagar galipremsagar marked this pull request as ready for review December 16, 2024 16:12
@galipremsagar galipremsagar requested a review from a team as a code owner December 16, 2024 16:12
@galipremsagar galipremsagar added bug Something isn't working and removed improvement Improvement / enhancement to an existing function labels Dec 16, 2024
@@ -207,11 +207,16 @@ def _from_columns_like_self(

@property
def level_names(self) -> tuple[abc.Hashable, ...]:
if self.is_cached("to_pandas_index"):
return self.to_pandas_index.names
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason we want/need to use the cached to_pandas_index here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, when updates to the pandas object created by to_pandas_index are performed, we need the updated names, that's what this piece of code does.

@mroeschke
Copy link
Contributor

I think this may close #14012 too

Co-authored-by: Matthew Roeschke <[email protected]>
Copy link
Contributor

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@galipremsagar
Copy link
Contributor Author

Just https://github.com/rapidsai/cudf/pull/17597/files#r1887795031 otherwise LGTM

Done 👍 Sorry that slipped my radar.

@galipremsagar galipremsagar added the 5 - Ready to Merge Testing and reviews complete, ready to merge label Dec 19, 2024
@galipremsagar
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 8e9254b into rapidsai:branch-25.02 Dec 19, 2024
107 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge bug Something isn't working non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BUG] Unable to set the names attribute of DataFrame.columns
2 participants